from fastapi import APIRouter

from ..util.response import success_response
from ..repository.characterCard_repository import character_card_repo

from config import app_config  # 假设有一个配置文件，包含数据库路径等

# 创建路由对象，可指定统一前缀
router = APIRouter(prefix="/character/cards", tags=["角色卡相关接口"])

@router.post("")
async def create_character_card(character_card: dict):
    """
    创建角色卡
    """
    character_card_repo.create_character_card(character_card)
    return success_response(message="角色卡创建成功")

@router.get("")
async def list_character_cards():
    """
    查询所有的角色卡
    """
    character_cards = character_card_repo.get_all_character_cards()
    # 这里可以调用相应的服务层函数来处理查询角色卡的逻辑
    return success_response(data=character_cards)

@router.get("/name/{name}")
async def list_character_cards_by_name(name:str):
    """
    通过角色名：，查询所有的角色卡
    """
    character_cards = character_card_repo.get_character_card_by_name(name=name)
    # 这里可以调用相应的服务层函数来处理查询角色卡的逻辑
    return success_response(data=character_cards)

@router.get("/enable")
async def list_character_cards_by_enable():
    """
    查询所有启用的角色卡
    """
    character_cards = character_card_repo.get_enabled_character_cards()
    # 这里可以调用相应的服务层函数来处理查询角色卡的逻辑
    return success_response(data=character_cards)

@router.get("/characterId/{character_id}")
async def get_character_card(character_id: int):
    """
    查询指定角色卡
    """
    character_card = character_card_repo.get_character_card_by_id(character_id)
    # 这里可以调用相应的服务层函数来处理查询角色卡的逻辑
    return success_response(data=character_card)

@router.delete("/{character_id}")
async def delete_character_card(character_id: int):
    """character_id
    删除角色卡,逻辑删除
    """
    character_card_repo.delete_character_card(character_id)
    # 这里可以调用相应的服务层函数来处理删除角色卡的逻辑
    return success_response(message="角色卡删除成功")


@router.put("/{character_card_id}")
async def update_character_card(character_card_id: int, character_card: dict):
    """
    修改角色卡
    """
    character_card_repo.update_character_card(
        character_id=character_card_id,
        name = character_card.get("name"),
        faction = character_card.get("faction"),
        title = character_card.get("title"),
        personality = character_card.get("personality"),
        speech_style = character_card.get("speech_style"),
        background = character_card.get("background"),
        interaction_rules = character_card.get("interaction_rules"),
        catchphrases = character_card.get("catchphrases"),
        behavior_patterns = character_card.get("behavior_patterns"),
        prohibited = character_card.get("prohibited"),
        dialogue_examples = character_card.get("dialogue_examples"),
        temperature = character_card.get("temperature"),
        top_p = character_card.get("top_p")
        )
    # 这里可以调用相应的服务层函数来处理修改角色卡的逻辑
    return success_response(message="角色卡修改成功")

@router.put("/band/{character_card_id}")
async def band_character_card(character_card_id: int):
    """
    禁用角色卡
    """
    character_card_repo.band_character_card(character_card_id)
    # 这里可以调用相应的服务层函数来处理修改角色卡的逻辑
    return success_response(message="禁用角色卡成功")


@router.put("/start/{character_card_id}")
async def start_character_card(character_card_id: int):
    """
    启动角色卡
    """
    character_card_repo.start_character_card(character_card_id)
    # 这里可以调用相应的服务层函数来处理修改角色卡的逻辑
    return success_response(message="启动角色卡成功")